<?php

namespace home\controllers;

use home\models\News;
use Yii;
use yii\data\ActiveDataProvider;
use yii\web\Controller;

/**
 * Site controller
 */
class NewsController extends Controller
{

    /**
     * @return string
     */
    public function actionIndex()
    {
        $dataProvider = new ActiveDataProvider([
            'query' => News::find()->where(['status' => News::STATUS_ACTIVE])->orderBy(['id' => SORT_DESC]),
        ]);

        return $this->render('index', [
            'data' => $dataProvider->getModels(),
            'pager' => $dataProvider->getPagination(),
        ]);
    }

    /**
     * @return string
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'data' => News::findOne($id),
        ]);
    }
}
